//
//  CYCommon.h
//  CreditAddressBook
//
//  Created by Lee on 15/4/20.
//  Copyright (c) 2015年 Lee. All rights reserved.
//

//判断是否为iOS8
#define IOS8 ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0)
//判断是否为iOS9
#define IOS9 ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0)

#define LENavigationH 64.f

#ifndef __IPHONE_9_0
#define __IPHONE_9_0 90000
#endif

#define IS_IOS9 __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0

//自定义LOG
#ifdef DEBUG
#define CYLog(...) NSLog(__VA_ARGS__)
#else
#define CYLog(...)
#endif

//授权失败提示
#define CYFailureCue @"无法读取到您的通讯录信息，为了您有更好的体验，请先到\n[设置]-[隐私]-[通讯录]\n允许该App使用通讯录信息。"
#define CYFailureLocation @"无法获取到您的位置信息，请先到\n[设置]-[隐私]-[位置]\n允许该App获取位置信息。"

//提示框按钮
#define CYToolTips @"知道了"

//定义颜色函数
#define CYColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

//定义导航栏按钮的tag
#define CYTabBarItemTagA 0
#define CYTabBarItemTagB 1
#define CYTabBarItemTagC 2

/**选中的字体颜色*/
#define SELTitleColor [UIColor colorWithRed:71/255.0 green:192/255.0 blue:102/255.0 alpha:1]

//Navi主体色调
#define CYNaviThemeColor CYColor(99, 207, 106, 1.0)
#define CYNaviThemeColorWithAlpha(a) CYColor(99, 207, 106, a)
#define CYNaviThemeColor1 CYColor(129, 196, 107, 1.0)
#define CYNaviThemeColorAndroid CYColor(127, 198, 106, 1.0)
//#define CYNaviThemeColorWithAlpha(a) CYColor(129, 196, 107, a)
//Navigation字体
#define CYNaviFont [UIFont boldSystemFontOfSize:17]
//Navigation字体颜色
#define CYNaviTitleColor [UIColor whiteColor]

//tabBar字体
#define CYTabBarTitleFont [UIFont systemFontOfSize:10]

//通知
#define CYNotificationCenter [NSNotificationCenter defaultCenter]

//自定义Error
#define CYErrorNil [NSError errorWithDomain:@"jsonFailMsg" code:-1 userInfo:@{@"message":@"没有更多数据"}]
#define CYError(m, c) [NSError errorWithDomain:@"jsonFailMsg" code:c userInfo:@{@"message":m}]

//屏幕size
#define CYScreeSize [UIScreen mainScreen].bounds.size

//提示框
#define CYAlertView(m) [[[UIAlertView alloc] initWithTitle:nil message:m delegate:nil cancelButtonTitle:CYToolTips otherButtonTitles:nil] show];

//判断字符串是否相同
#define CYStringEqualTo(a, b) [a isEqualToString:b]
#define CYStringFormat(a, b ...) [NSString stringWithFormat:a, b]

//NSString -> NSURL
#define CYURLWithString(u) [NSURL URLWithString:u]

#define CYURLWithService(u) CYURLWithString([CYUSERIMAGEBASIC stringByAppendingString:u])

//nsstring -> nsurlold
#define CYURLWithStringold(u) [NSURL URLWithString:u]
#define CYURLWithServiceold(u) CYURLWithString([CYSTATICPATHBASIC stringByAppendingString:u])




#define CYURLWithUserService(u) CYURLWithString([CYUSERIMAGEBASIC stringByAppendingString:u])

//沙盒
#define CYUserDefaultsAddObj(obj, key) \
NSUserDefaults *deft = [NSUserDefaults standardUserDefaults]; \
[deft setObject:obj forKey:key]; \
[deft synchronize]; \

#define CYUserDefaultsGetObj(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]

//weakSelf
#define CYWeakObject(name, obj) __unsafe_unretained __typeof(obj) name = obj

//切换到主线程
#define dispatch_main_sync_safe_le(block)\
if ([NSThread isMainThread]) {\
block();\
}\
else {\
dispatch_sync(dispatch_get_main_queue(), block);\
}

//获取APP版本号
#define APPVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
//接口版本号
#define APIVersion APPVersion

//付费成功通知
extern NSString *const CYFufeiNotification;

//运营商通知
extern NSString *const CYYYSNotification;

//新版本上传通知
extern NSString *const CYPersonalNotification;
extern NSString *const CYNewAssetNotification;
extern NSString *const CYNewWorkNotification;

extern NSString *const CYNickNameDidChangeNotification;//用户昵称变化监听中心Key
extern NSString *const CYChangedNickName;//用户昵称监听Key
extern NSString *const CYChangedHeadPic;//用户头像监听Key

extern NSString *const CYTabBarChangeNotification;//用户输入电话号码时发出通知Key
extern NSString *const CYEditTabBarShow;//显示编辑TabBar监听Key

extern NSString *const CYCityDidChangeNotification;
extern NSString *const CYSelectCityName;

//通知KEY
extern NSString *const CYUserNameKey;//用户信息KEY
extern NSString *const CYPasswordKey;
extern NSString *const CYUserKey;
extern NSString *const CYAreaInfoKey;//城市定位信息Key
extern NSString *const CYSimpleRecordsDicKey;//simpleRecord字典保存key
extern NSString *const CYCallStateDisconnectedKey;//通话结束Key
extern NSString *const CYAddressBookChangeNotification;//通讯录改变通知
extern NSString *const CYAddressBookImageKey;
extern NSString *const CYAddressBookPhoneKey;
extern NSString *const CYCollectionNotification;//收藏通知
extern NSString *const CYCardBandNotification;//绑定银行卡通知
extern NSString *const CYDealCodeNotification;//设置交易密码通知
extern NSString *const CYDialNotification;//拨号通知
extern NSString *const CYCallRecordChangeNotification;//通话记录变更通知
extern NSString *const CYAddPersonNotification;//新增联系人通知
extern NSString *const nCYReloadDataOfCarLeaseAndDrop;//租车列表首页刷新
extern NSString *const CYAssetAccountNotification;//余额刷新通知;
//提交类通知
extern NSString *const CYAssetNotification;
extern NSString *const CYPersonNotification;
extern NSString *const CYWorkNotification;
extern NSString *const CYOhterNotification;
extern NSString *const CYGenealNotification;

//推送通知
extern NSString *const CYPushNotification;

/** 城市改变通知 */
extern NSString *const MTCityDidChangeNotification;
/** 城市 */
extern NSString *const MTSelectCityName;

//提示框提示信息
extern NSString *const CYServerConnectFailure;
extern NSString *const CYServerConnectTimeOver;
extern NSString *const CYUndeveloped;

extern NSString *const kCYNOLOGIN;//没有登录
extern NSString *const kCYLoginStatusError;//没有登录提示信息

extern NSString *const nCYCreditSearch;//信用系统搜索通知
extern NSString *const kCYCreditSearch;//信用系统搜索的关键字

extern NSString *const nCYLogout;//用户登出通知

/**
 *  汇信
 */
extern NSString *const CYTabBarTitleA;
/**
 *  通讯录
 */
extern NSString *const CYTabBarTitleB;
/**
 *  我
 */
extern NSString *const CYTabBarTitleC;
/**
 *  通话
 */
extern NSString *const CYTabBarTitleD;
/**
 *  删除
 */
extern NSString *const CYTabBarTitleE;
/**
 *  发现
 */
extern NSString *const CYTabBarTitleF;
//信用查询
extern NSString *const CYTabBarTitleG;


/**姓名为空*/
extern NSString *const CYPhoneNameNil;

/**通讯录是否已同步key*/
extern NSString *const CYCloudSynKey;

/**
 *  百度开发编号
 */
extern NSString *const ak;
extern NSString *const UMAppkey;//友盟Appkey

typedef enum {
    /**超时*/
    CYErrorCodeOverTime = -1001,
    /**服务器链接失败*/
    CYErrorCodeErrorFromService = -1002,
    /**无数据*/
    CYErrorCodeNOData = -1,
    /**参数接收失败*/
    CYErrorCodeParamsError = -1003,
    /**网络中断*/
    CYErrorCodeNetInterrupt = -1005,
    /**内部错误*/
    CYErrorCodeError = -1006,
    /**用户没有登陆*/
    CYErrorCodeNoLogin = -1007
}CYErrorCode;

typedef enum {
    CYIndexFirst = 0,
    CYIndexSecond,
    CYIndexThird,
    CYIndexFourth
}CYIndex;

typedef NS_ENUM(NSInteger, CYUserType) {
    CYUserTypePerson = 0,
    CYUserTypeCompany = 1,
};

typedef NS_ENUM(NSInteger, CYPushType) {
    CYPushTypePush = 0,
    CYPushTypePresent,
};
